import React, {useState} from 'react'
import {useHistory} from 'react-router-dom'
import {putAccAdvertisingAddAdvertising} from '../../../../financialApi'
import { Button, Form, Input, InputNumber, message } from 'antd'

const { TextArea } = Input;

/**
 * @description: 财务-推广-费用申请
 * @author: xiaoxujs
 * @upDate: xiaoxujs（2021-07-07）
 */

const Popularize = () => {
    const history = useHistory()
    const [buttonLoading, setButtonLoading] = useState(false)
    
    const onFinish = (values) => {
        ;(async () => {
            setButtonLoading(true)
            const {code , msg} = await putAccAdvertisingAddAdvertising(values)
            if(code === '20000') {
                message.success('提交成功')
                setButtonLoading(false)
                history.go('-1')
            }else{
                setButtonLoading(false)
                message.error(msg)
            }
        })()
    };
    return <Form
        labelCol={{ span: 3 }}
        wrapperCol={{ span: 16 }}
        onFinish={onFinish}
    >
                <Form.Item
            label="借款事由"
            name="matter"
            rules={[{ required: true, message: '请输入借款事由!' }]}
        >
            <TextArea />
        </Form.Item>
        <Form.Item
            label="借款金额（元）"
            name="money"
            rules={[{ required: true, message: '请输入借款金额!' }]}
        >
            <InputNumber />
        </Form.Item>
        <Form.Item
            label="供应商"
            name="supplier"
        >
            <Input />
        </Form.Item>
        <Form.Item
            label="推广形式"
            name="way"
            rules={[{ required: true, message: '请输入推广方式!' }]}
        >
            <Input />
        </Form.Item>
        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
            <Button type="primary" htmlType="submit" loading = {buttonLoading}>
                提交申请
            </Button>
        </Form.Item>
    </Form>
}

export default Popularize